import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import './assets/css/reset.css';
import axios from 'axios'
import asyncValidator from 'async-validator'

Vue.config.productionTip = false;

Vue.use(ElementUI);

//封装提交数据的axios函数
var instance = axios.create({
	baseURL: 'http://yaochiwan2.bluej.cn',
  headers: {Authorization:"Bearer "+ sessionStorage.getItem('token')}
});
Vue.prototype.$submit = instance;

//封装请求所有数据的axios函数
var require = axios.create({
	baseURL: 'http://yaochiwan2.bluej.cn'
});
Vue.prototype.$require = require;

router.beforeEach((to,from,next)=>{
	//用sessionStorage保存的token验证是否需要登录
	if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
    if(sessionStorage.getItem('token')){ // 查询本地存储信息是否已经登陆
    	document.title = to.meta.title;
      next();
    }else{
      next({
        path: '/login' // 未登录则跳转至login页面
        });
			document.title = to.meta.title;
    }
	}else{
	    document.title = to.meta.title;
	    next();
	}
	
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')